package com.smarttourism.service;

import com.smarttourism.domain.Customer;
import com.smarttourism.mapper.CustomerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomerService {
    @Autowired
    private CustomerMapper customerMapper;

    public List<Customer> findCustomers(String name){
        List<Customer> customers = customerMapper.findCustomers(name);
        if (customers!=null){
            for (Customer customer : customers) {
                customer.setCustomerRange(customerMapper.findCustomerRangeByRangeId(customer.getCrange()));
                customer.setCustomerIdType(customerMapper.findCustomerIdTypeByTypeId(customer.getIdType()));
            }
        }
        return customers;
    }
    public int insertCustomer(Customer customer){
        return  customerMapper.insertSelective(customer);
    }

    public int deleteCustomers(Integer[] ids){
        return customerMapper.updateDelByids(ids);
    }

    public int updateCustomer(Customer customer){
        return customerMapper.updateByPrimaryKeySelective(customer);
    }

    public int deleteCustomer(int id){
        return customerMapper.updateDelByid(id);
    }

}
